// 本文件由自动工具 proto.py 自动生成，请勿修改
// filename test1_csbuf.go
// package test

package test

import (
	"git.oschina.net/wint/go-csbuf/csbuf"
)

// message Head
type Head struct {
	A uint32 `json:"a"`
	B string `json:"b"`
}

func (m *Head) GetProtoId() uint16 {
	return 1000
}

func (m *Head) Marshal(w *csbuf.CsbufParser) {
	w.SetUint32(m.A, 1)
	w.SetString(m.B, 2)
}

func (m *Head) Unmarshal(r *csbuf.CsbufParser) {
	m.A = r.GetUint32(1)
	m.B = r.GetString(2)
}

func NewHead() csbuf.CsbufMessage {
	return &Head{}
}

// message Test1
type Test1 struct {
	A_t1 uint8 `json:"a_t1"`
	At_2 uint32 `json:"at_2"`
	At3_ string `json:"at3_"`
	T4 []uint32
	T5 []string
	T6 *Head
	T7 []*Head
}

func (m *Test1) GetProtoId() uint16 {
	return 2001
}

func (m *Test1) Marshal(w *csbuf.CsbufParser) {
	w.SetUint8(m.A_t1, 1)
	w.SetUint32(m.At_2, 2)
	w.SetString(m.At3_, 3)
	w.SetArray(uint8(len(m.T4)), 4)
	for _, v := range m.T4 {
		w.SetUint32(v, 0)
	}
	w.SetArray(uint8(len(m.T5)), 5)
	for _, v := range m.T5 {
		w.SetString(v, 0)
	}
	w.SetMessage(6)
	if m.T6 != nil {
		m.T6.Marshal(w)
	}
	w.EndSetMessage()
	w.SetArray(uint8(len(m.T7)), 7)
	for _, v := range m.T7 {
		w.SetMessage(0)
		v.Marshal(w)
		w.EndSetMessage()
	}
}

func (m *Test1) Unmarshal(r *csbuf.CsbufParser) {
	m.A_t1 = r.GetUint8(1)
	m.At_2 = r.GetUint32(2)
	m.At3_ = r.GetString(3)
	countT4 := int(r.GetArray(4))
	for i := 0; i < countT4; i++ {
		m.T4 = append(m.T4, r.GetUint32(0))
	}
	countT5 := int(r.GetArray(5))
	for i := 0; i < countT5; i++ {
		m.T5 = append(m.T5, r.GetString(0))
	}
	r.GetMessage(6)
	if m.T6 == nil {
		m.T6 = new(Head)
	}
	m.T6.Unmarshal(r)
	r.EndGetMessage()
	countT7 := int(r.GetArray(7))
	for i := 0; i < countT7; i++ {
		msg := new(Head)
		r.GetMessage(0)
		msg.Unmarshal(r)
		r.EndGetMessage()
		m.T7 = append(m.T7, msg)
	}
}

func NewTest1() csbuf.CsbufMessage {
	return &Test1{}
}

// message Test2
type Test2 struct {
	A_t1 uint8 `json:"a_t1"`
	At_2 uint32 `json:"at_2"`
	At3_ string `json:"at3_"`
	T6 *Head
	T7 []*Head
}

func (m *Test2) GetProtoId() uint16 {
	return 2002
}

func (m *Test2) Marshal(w *csbuf.CsbufParser) {
	w.SetUint8(m.A_t1, 1)
	w.SetUint32(m.At_2, 2)
	w.SetString(m.At3_, 3)
	w.SetMessage(6)
	if m.T6 != nil {
		m.T6.Marshal(w)
	}
	w.EndSetMessage()
	w.SetArray(uint8(len(m.T7)), 7)
	for _, v := range m.T7 {
		w.SetMessage(0)
		v.Marshal(w)
		w.EndSetMessage()
	}
}

func (m *Test2) Unmarshal(r *csbuf.CsbufParser) {
	m.A_t1 = r.GetUint8(1)
	m.At_2 = r.GetUint32(2)
	m.At3_ = r.GetString(3)
	r.GetMessage(6)
	if m.T6 == nil {
		m.T6 = new(Head)
	}
	m.T6.Unmarshal(r)
	r.EndGetMessage()
	countT7 := int(r.GetArray(7))
	for i := 0; i < countT7; i++ {
		msg := new(Head)
		r.GetMessage(0)
		msg.Unmarshal(r)
		r.EndGetMessage()
		m.T7 = append(m.T7, msg)
	}
}

func NewTest2() csbuf.CsbufMessage {
	return &Test2{}
}

